package leetcode.editor.week.week315;

import java.util.HashSet;
import java.util.Set;

// 6204. 与对应负数同时存在的最大正整数
// https://leetcode.cn/problems/largest-positive-integer-that-exists-with-its-negative/
public class Solution6204 {
    public int findMaxK(int[] nums) {
        Set<Integer> set = new HashSet<>();
        for (int num : nums) {
            if (num > 0) set.add(num);
        }

        int ans = -1;
        for (int num : nums) {
            if (num < 0) {
                if (set.contains(-num)) {
                    ans = Math.max(ans, -num);
                }
            }
        }

        return ans;
    }
}
